package chapter3;

public class IntegerStack implements Cloneable {
    private int[] buffer;
    private int top;
    
    public IntegerStack(int maxContents){
        buffer = new int[maxContents];
        top = -1;
    }
    
    public void push(int val){
        buffer[++top] = val;
    }
    
    public int pop(){
        return buffer[top--];
    }
    
    public IntegerStack clone(){
        try{
            //don't create by new
            IntegerStack nObj = (IntegerStack) super.clone();
            nObj.buffer = buffer.clone();
            return nObj;
        }catch(CloneNotSupportedException e){
            //can't happen -- we support clone and so do arrays
            return null;
        }
    }
}
